package com.xxxx.service.impl;

import com.baomidou.mybatisplus.extension.api.R;
import com.xxxx.mapper.DepartmentMapper;
import com.xxxx.pojo.Department;
import com.xxxx.pojo.RespBean;
import com.xxxx.service.IDepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-05-21
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<Department> getAllDepartment() {
        return departmentMapper.getAllDepartment(-1);
    }

    @Override
    public RespBean addDepartment(Department department) {
        department.setEnabled(true);
        departmentMapper.addDepartment();
        if (1==department.getResult()){
            return RespBean.success("添加成功",department);
        }
        return RespBean.error("添加失败");
    }

    @Override
    public RespBean deleteDep(Integer id) {
        Department department = new Department();
        department.setId(id);
        departmentMapper.deleteDep();
        if (-2==department.getResult()){
            return RespBean.error("删除失败，该部门下还有子部门");
        }
        if (-1==department.getResult()){
            return RespBean.error("删除失败，该部门下还有员工");
        }
        if (1==department.getResult()){
            return RespBean.success("删除成功");
        }

        return RespBean.error("删除失败");
    }


}
